<template>
	<div class="ALpage-content">
		<ul>
			<li>帖子列表</li>
		</ul>
		<div class="layui-card-body ">
			<table class="layui-table layui-form">
				<thead>
					<tr style="height: 39px;">
						<th>
							<input style="width: 25px;height: 25px;" type="checkbox" name="" lay-skin="primary">
						</th>
						<th v-for="item in colnums">
							{{item.name}}
						</th>
					</tr>
				</thead>
				<tbody>
					<tr v-for="item in posts">
						<td>
							<input style="width: 25px;height: 25px;" type="checkbox" :checked="item.isSelect" name="" lay-skin="primary">
						</td>
						<td>{{item.title}}</td>
						<td>{{item.userVo.username}}</td>
						<td>
							<div v-if="item.status == 0">
								未审核
							</div>
							<div v-else-if="item.status == 1">
								审核通过
							</div>
							<div v-else>
								审核未通过
							</div>
						</td>
						<td>
							<button class="ALauditButtonAllow" v-if="item.status == 0 || item.status == 2" @click="allowAudit(item)">
								允许通过
							</button>
							<button class="ALauditButton" style="position: relative; left: 10px;" v-if="item.status == 10 || item.status == 0"
							 @click="refuseAudit(item)">
								拒绝通过
							</button>

						</td>
					</tr>
				</tbody>
			</table>
			<div class="layui-card-body ">
				<div class="page">
					<button @click="upPageAction()">
						<< </button> <button v-bind:class='{current:(currentIndex-1)==index}' v-for="(item,index) in pages" @click="jumpPageAction(item,index)">{{item.name}}
					</button>
					<button @click="nextPageAction()"> >> </button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import HTTPUtil from '../../js/HttpUtil.js'
	import UserInfoManagerAdmin from '../../js/UserInfoManagerAdmin.js'
	import AesUtil from '../../js/AesUtil.js'
	export default {
		data() {
			return {
				currentIndex: 1,
				pageInfo: {
					lastPage: true,
					nextPage: 1,
					prePage: 1,
					totalPage: 1
				},
				pages: [{
					name: 'test'
				}],
				colnums: [{
					name: '作品名称'
				}, {
					name: '作者'
				}, {
					name: '审核状态'
				}, {
					name: '操作'
				}],
				posts: [{
					isSelect: true,
					title: '第一个作品',
					userVo: {"id":85,"sex":2,
"headUrl":"http://120.79.79.211/img/defaultAdminHead.png",
"createTime":"2020-02-10 06:24:28:000",
"username":"John C.L. Apple1",
},
					status: 1
				}]

			}
		},
		methods: {
			allowAudit: function(item) {
				console.log(item.name);
				//1通过审核
				this.setAuditAction(item, 1);
			},
			refuseAudit: function(item) {
				console.log(item.name);
				//2代表拒绝通过
				this.setAuditAction(item, 2);
			},
			upPageAction: function() {
				this.currentIndex = this.pageInfo.prePage;
				this.getProductListIndex();

			},
			nextPageAction: function() {
				this.currentIndex = this.pageInfo.nextPage;
				this.getProductListIndex();
			},
			jumpPageAction: function(item, index) {
				console.log(item.name);
				this.currentIndex = index + 1;
				this.getProductListIndex();

			},
			setAuditAction: function(item, audit) {
				var params = new URLSearchParams();
				params.append('sessionkey', UserInfoManagerAdmin.getInfo().userExt.sessionKey);
				params.append('sharePostId', item.id);
				params.append('auditStatus', audit);
				HTTPUtil.post('sharePost/updateStatus.do', params)
					.then(response => {
						console.log('图片s：' + JSON.stringify(response.data));

						if (response.data.code == 0) {
							//修改成功
							item.status = audit;
						}
					}).catch(function(error) {
						console.log(error);
					});
			},
			getProductListIndex: function() {
				console.log("useradmin=", UserInfoManagerAdmin.getInfo())
				var params = new URLSearchParams();
				params.append('sessionkey', UserInfoManagerAdmin.getInfo().userExt.sessionKey);
				params.append('pageNumber', this.currentIndex);
				params.append('pageSize', '12');
				HTTPUtil.post('sharePost/list.do', params)
					.then(response => {
						var tempData = response.data.data;
						if (response.data.isEny == true) {
							tempData = response.data.enydata;
							tempData = AesUtil.decryptAES(tempData);
							tempData = JSON.parse(tempData);
						}
						console.log("tempData=", tempData);
						if (response.data.code == 0) {
							let list = tempData;
							for (let s of list) {
								s.isSelect = false
							}
							this.posts = tempData;
							let paginationVo = response.data.paginationVo;
							this.pageInfo = paginationVo;
							this.pages = [];
							for (var i = 0; i < this.pageInfo.totalPage; i++) {
								var object = {};
								object.name = i + 1;
								this.pages.push(object);
							}
						}
					}).catch(function(error) {
						console.log(error);
					});
			}
		},
		mounted() {
			this.getProductListIndex();
		}
	}
</script>

<style>
	/* @import "../css/APostList.css"; */
	@import "../css/AHome.css";
</style>
